<template>
  <div>
    <el-dialog :visible.sync="open" @close="close" title="知识库文档搜索" width="80%" append-to-body destory-on-close>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="80px">
        <el-form-item label="关键词" prop="aerodromeid">
          <el-input type="text" v-model="keyword" placeholder="请输入关键词" :style="{ width: '100%' }"> </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="list">
        <el-table-column label="文档类型" align="center" prop="verno" width="140">
          <template slot-scope="scope">
            {{ getDocType(scope.row.type) }}
          </template>
        </el-table-column>
        <el-table-column label="文档标题" prop="title" />
        <el-table-column label="更新时间" align="center" prop="time" width="180" />
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleDocView(scope.row)">查看文档 </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="handleQuery" />
    </el-dialog>
    <covenant-detail ref="convenantDetail" />
    <doc-detail ref="docDetail" />
    <law-detail ref="lawDetail" />
    <management-system-detail ref="managementSystemDetail" />
    <standard-detail ref="standardDetail" />
    <common-detail ref="commonDetail" />
  </div>
</template>

<script>
import dialogMixin from "@/mixins/dialogMixin";
import * as KnoApi from "@/api/kno/doc";
import CovenantDetail from "@/views/kno/components/covenantDetail.vue";
import DocDetail from "@/views/kno/components/docDetail.vue";
import LawDetail from "@/views/kno/components/lawDetail.vue";
import ManagementSystemDetail from "@/views/kno/components/managementsystemDetail.vue";
import StandardDetail from "@/views/kno/components/standardDetail.vue";
import CommonDetail from "@/views/kno/components/commonDetail.vue";
export default {
  name: "DocSearchDialog",
  mixins: [dialogMixin],
  components: {
    CovenantDetail,
    DocDetail,
    LawDetail,
    ManagementSystemDetail,
    StandardDetail,
    CommonDetail,
  },
  data() {
    return {
      title: "",
      list: [],
      keyword: "",
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
    };
  },
  methods: {
    show() {
      this.open = true;
    },
    handleDocView(data) {
      switch (data.type) {
        case "covenant":
          this.$refs.convenantDetail.show(data.id);
          break;
        case "doc":
          this.$refs.docDetail.show(data.id);
          break;
        case "law":
          this.$refs.lawDetail.show(data.id);
          break;
        case "managementsystem":
          this.$refs.managementSystemDetail.show(data.id);
          break;
        case "standard":
          this.$refs.standardDetail.show(data.id);
          break;
        case "common":
          this.$refs.commonDetail.show(data.id);
          break;
      }
    },
    getDocType(type) {
      let mimes = [
        { label: "案例库", value: "case" },
        { label: "国际民航公约", value: "covenant" },
        { label: "知识库文档", value: "doc" },
        { label: "法律法规", value: "law" },
        { label: "管理制度", value: "managementsystem" },
        { label: "标准规范", value: "standard" },
        { label: "应急常识", value: "common" },
      ];
      let mime = mimes.find(val => val.value == type);
      return mime.label;
    },
    handleQuery() {
      // KnoApi.docSearch(this.keyword, this.queryParams).then(res => {
      //   this.list = res.data;
      // })
    },
  },
};
</script>

<style lang="scss" scoped></style>
